package com.jensen.metaq.example;

import com.jensen.metaq.example.util.DateUtil;
import com.taobao.metamorphosis.Message;
import com.taobao.metamorphosis.client.consumer.MessageConsumer;
import com.taobao.metamorphosis.client.consumer.MessageListener;
import com.taobao.metamorphosis.exception.MetaClientException;

import java.util.concurrent.Executor;

/**
 * Created by szhua on 2016/6/8.
 */
public class AsynConsumer {


    public static void main(String[] args) throws MetaClientException {

        String topic="meta-test";
        MessageConsumer consumer=MessageFactory.getMessageConsumerInstance();
        if (consumer!=null){
            consumer.subscribe(topic, 1024 * 1024, new MessageListener() {

                @Override
                public void recieveMessages(final Message message) {
                    System.out.println(DateUtil.getCurrentTime()+" Receive message " + new String(message.getData()));
                }


                @Override
                public Executor getExecutor() {
                    // Thread pool to process messages,maybe null.
                    return null;
                }
            });
            // complete subscribe
            consumer.completeSubscribe();
        }
    }



}
